//
//  VideoDetailCommentCell.m
//  copyrightTrading
//
//  Created by edz on 2020/10/9.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "VideoDetailCommentCell.h"

@interface VideoDetailCommentCell ()
@property (nonatomic, strong) UIImageView *img;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@end

@implementation VideoDetailCommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    UIView *bgView = [UIView new];
    bgView.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.top.offset(0);
    }];
    
    self.img = [[UIImageView alloc] init];
    self.img.backgroundColor = UIColor.brownColor;
    self.img.layer.masksToBounds = YES;
    self.img.layer.cornerRadius = 24;
    [bgView addSubview:self.img];
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.top.offset(20);
        make.width.height.mas_equalTo(48);
    }];
    
    self.nameLabel = [UILabel new];
    self.nameLabel.font = JSS_MEDIUM_FONT_3;
    self.nameLabel.text = @"123木头人";
    [bgView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.img.mas_right).offset(20);
        make.top.equalTo(self.img.mas_top).offset(0);
        make.height.mas_equalTo(18);
    }];
    self.nameLabel.preferredMaxLayoutWidth = kDeviceWidth - 210;
    [self.nameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

    self.dateLabel = [UILabel new];
    self.dateLabel.font = JSS_MEDIUM_FONT_3;
    self.dateLabel.textColor = RGB_VALUE(0xA5A5A5);
    self.dateLabel.text = @"2020-09-20 9:00";
    [bgView addSubview:self.dateLabel];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(20);
        make.top.equalTo(self.nameLabel.mas_top);
        make.height.mas_equalTo(15);
        make.right.offset(-20);
    }];
    
    self.contentLabel = [UILabel new];
    self.contentLabel.font = JSS_MEDIUM_FONT_3;
    self.contentLabel.text = @"大神比较牛";
    self.contentLabel.numberOfLines = 0;
    [bgView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(3);
        make.height.mas_equalTo(18);
        make.right.offset(-20);
    }];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = RGB_VALUE(0xDBDBDB);
    [self.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.right.offset(-20);
        make.height.mas_equalTo(1);
        make.bottom.offset(0);
    }];
}

- (void)setDataDic:(NSDictionary *)dataDic
{
    _dataDic = dataDic;
    [self.img m_setImageWithUrlString:dataDic[@"head_img"] placeholder:@"placeholderImg"];
    self.nameLabel.text = dataDic[@"nickname"];
    self.dateLabel.text = dataDic[@"create_at"];
    NSString *dd = dataDic[@"content"];
    CGSize sizes = [dataDic[@"content"] boundingRectWithSize:CGSizeMake(kDeviceWidth - 100, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:JSS_MEDIUM_FONT_3} context:nil].size;
    self.contentLabel.text = dd;
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(sizes.height);
    }];
}
@end
